<?php
$this->breadcrumbs=array(
	'NID列表'=>array('nid'),
);
if($model->isNewRecord){
	$title = '新增NID';
}else{
	$title = '更新NID';
}
?>

<h1><?=$title?></h1>
<div style="width:100%; float:left; margin-bottom:10px; text-align:right;">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'nid-form',
	'htmlOptions'=>array('name'=>'jobForm','onsubmit'=>'return fxl();'),
	'enableAjaxValidation'=>false,
)); ?>
	<?php echo $form->errorSummary($model); ?>

	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>			
			<td width="18%" class="td_right"><?php echo $form->label($model,'Date'); ?>: </td>
			<td width="32%">
				<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
						'attribute' => 'Date',
						'model'=>$model,
						'language'=>'zh',
						'options' => array(
								'showAnim' => 'fold',
								'dateFormat' => 'yymmdd',
						),
						'htmlOptions'=>array(
							'readonly'=>'readonly',
							'class'=>'input_size10'
						),
				));
				?>
			</td>
			<td width="18%" class="td_right"><?php echo $form->label($model,'NIDNum'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'NIDNum',array('class'=>'input_size10 disabled','disabled'=>'disabled')); ?>
			</td>
		</tr>		
		<tr>
			<td class="td_right"><?php echo $form->label($model,'RCMDPerson'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'RCMDPerson',array('class'=>'input_size10')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'CheckPerson'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'CheckPerson',array('class'=>'input_size10')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'Category'); ?>: </td>
			<td>
				<?php
				echo $form->dropDownList($model, 'Category', $data['classes'], array(
					'empty' => '请选择',
					'class'=>'input_size11',
					'ajax' => array(
						'url' => Yii::app()->createUrl('Psi/dynamicClass'),
						'data' => array('class' => 'js:this.value'),
						'update' => '#NID_SubCategory',
					),
				));
				?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'SubCategory'); ?>: </td>		
			<td>
				<?php echo $form->dropDownList($model, 'SubCategory', $data['subclasses'],array('empty'=>array(''=>'请选择'),'class'=>'input_size11')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'RCMDReason'); ?>: </td>
			<td colspan="3">
				<?php echo $form->textField($model,'RCMDReason',array('class'=>'input_size12')); ?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'RCMDLink'); ?>: </td>
			<td colspan="3">
				<?php echo $form->textField($model,'RCMDLink',array('class'=>'input_size12')); ?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'SuccessKeywords'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'SuccessKeywords',array('class'=>'input_size10')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'FailKeywords'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'FailKeywords',array('class'=>'input_size10')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'Analysis'); ?>: </td>
			<td colspan="3">
				<?php
				$this->widget('application.extensions.kindeditor4.KindEditorWidget',
						array('model' => $model,'attribute' => 'Analysis',
							'htmlOptions'=>array('width' => '100%'),
							'miniMode'=>true,'editorname'=>'Description'));
				?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'Summary'); ?>: </td>
			<td colspan="3">
				<?php
				$this->widget('application.extensions.kindeditor4.KindEditorWidget',
						array('model' => $model,'attribute' => 'Summary',
							'htmlOptions'=>array('width' => '100%'),
							'miniMode'=>true,'editorname'=>'Description'));
				?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'SubStatus'); ?>: </td>
			<td>
				<?php echo $form->dropDownList($model, 'SubStatus', Yii::app()->Params['subStatus'],array('class'=>'input_size11')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'Rank'); ?>: </td>		
			<td>
				<?php echo $form->dropDownList($model, 'Rank', Yii::app()->Params['rank'],array('empty'=>array(''=>'请选择'),'class'=>'input_size11')); ?>
			</td>
		</tr>
		<tr class="head">
			<td colspan="4">&nbsp;</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'AmazonS'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'AmazonS',array('class'=>'input_size10','onblur'=>'amazonc("NID_AmazonS")')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'AmazonL'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'AmazonL',array('class'=>'input_size10','onblur'=>'amazonc("NID_AmazonL")')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'EbayS'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'EbayS',array('class'=>'input_size10','onblur'=>'ebayc("NID_EbayS")')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'EbayL'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'EbayL',array('class'=>'input_size10','onblur'=>'ebayc("NID_EbayL")')); ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'Cost'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'Cost',array('class'=>'input_size10','onblur'=>'cost()')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'LACost'); ?>: </td>			
			<td id="NID_LACost">
				<?php echo $model->LACost; ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'WeightG'); ?>: </td>
			<td>
				<?php echo $form->textField($model,'WeightG',array('class'=>'input_size10','onblur'=>'weight()')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'WeightLB'); ?>: </td>			
			<td id="NID_WeightLB">
				<?php echo $model->WeightLB; ?>				
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'ShippingCost'); ?>: </td>			
			<td>
				<?php echo $form->textField($model,'ShippingCost',array('class'=>'input_size10','onblur'=>'profit()')); ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'ShippingFee'); ?>: </td>
			<td id="NID_ShippingFee">
				<?php echo $model->ShippingFee; ?>
			</td>			
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'ACommissionS'); ?>: </td>
			<td id="NID_AmazonS_C">
				<?php echo $model->ACommissionS; ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'ACommissionL'); ?>: </td>			
			<td id="NID_AmazonL_C">
				<?php echo $model->ACommissionL; ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'ECommissionS'); ?>: </td>
			<td id="NID_EbayS_C">
				<?php echo $model->ECommissionS; ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'ECommissionL'); ?>: </td>			
			<td id="NID_EbayL_C">
				<?php echo $model->ECommissionL; ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'AProfitS'); ?>: </td>
			<td id="AProfitS">
				<?php echo $model->AProfitS; ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'AProfitL'); ?>: </td>			
			<td id="AProfitL">
				<?php echo $model->AProfitL; ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'EProfitS'); ?>: </td>
			<td id="EProfitS">
				<?php echo $model->EProfitS; ?>
			</td>
			<td class="td_right"><?php echo $form->label($model,'EProfitL'); ?>: </td>			
			<td id="EProfitL">
				<?php echo $model->EProfitL; ?>
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'AGPPS'); ?>: </td>
			<td id="AGPPS">
				<?php echo $model->AGPPS; ?>%
			</td>
			<td class="td_right"><?php echo $form->label($model,'AGPPL'); ?>: </td>			
			<td id="AGPPL">
				<?php echo $model->AGPPL; ?>%
			</td>
		</tr>
		<tr>
			<td class="td_right"><?php echo $form->label($model,'EGPPS'); ?>: </td>
			<td id="EGPPS">
				<?php echo $model->EGPPS; ?>%
			</td>
			<td class="td_right"><?php echo $form->label($model,'EGPPL'); ?>: </td>			
			<td id="EGPPL">
				<?php echo $model->EGPPL; ?>%
			</td>
		</tr>
	</table>
	<div style="text-align:center;">
	<?php
	echo CHtml::submitButton($model->isNewRecord ? '新建' : '更新');
	?>
	</div>
<?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
/*<![CDATA[*/
var rate = '<?=Helper::getRate()?>';
function amazonc(id){
	var value = 0.17*$("#"+id).val();
	$("#"+id+"_C")[0].innerHTML=value.toFixed(2);
}
function ebayc(id){
	var value = 0.1*$("#"+id).val();
	$("#"+id+"_C")[0].innerHTML=value.toFixed(2);
}
function cost(){
	var value = 1.2*$("#NID_Cost").val()/rate;
	$("#NID_LACost")[0].innerHTML=value.toFixed(2);
}
function weight(){
	var value = 0.002205*$("#NID_WeightG").val();
	$("#NID_WeightLB")[0].innerHTML=value.toFixed(2);
    var fee = value*0.5+4.49;
    $("#NID_ShippingFee")[0].innerHTML=fee.toFixed(2);        
}
function profit(){
	var aprofits = parseFloat($("#NID_AmazonS").val())+parseFloat((0.002205*$("#NID_WeightG").val())*0.5+4.49)-parseFloat($("#NID_AmazonS").val()*0.17)-parseFloat($("#NID_ShippingCost").val())-parseFloat(1.2*$("#NID_Cost").val()/rate);
	$("#AProfitS")[0].innerHTML=aprofits.toFixed(2);
	
	var aprofitl = parseFloat($("#NID_AmazonL").val())+parseFloat((0.002205*$("#NID_WeightG").val())*0.5+4.49)-parseFloat($("#NID_AmazonL").val()*0.17)-parseFloat($("#NID_ShippingCost").val())-parseFloat(1.2*$("#NID_Cost").val()/rate);
	$("#AProfitL")[0].innerHTML=aprofitl.toFixed(2);
	
	var eprofits = parseFloat($("#NID_EbayS").val())-parseFloat($("#NID_EbayS").val()*0.1)-parseFloat($("#NID_ShippingCost").val())-parseFloat(1.2*$("#NID_Cost").val()/rate);
	$("#EProfitS")[0].innerHTML=eprofits.toFixed(2);
	
	var eprofitl = parseFloat($("#NID_EbayL").val())-parseFloat($("#NID_EbayL").val()*0.1)-parseFloat($("#NID_ShippingCost").val())-parseFloat(1.2*$("#NID_Cost").val()/rate);
	$("#EProfitL")[0].innerHTML=eprofitl.toFixed(2);
	
	var agpps = aprofits/(aprofits+parseFloat(1.2*$("#NID_Cost").val()/rate));
	$("#AGPPS")[0].innerHTML=(agpps*100).toFixed(2)+'%';
	
	var agppl = aprofitl/(aprofitl+parseFloat(1.2*$("#NID_Cost").val()/rate));
	$("#AGPPL")[0].innerHTML=(agppl*100).toFixed(2)+'%';
	
	var egpps = eprofits/(eprofits+parseFloat(1.2*$("#NID_Cost").val()/rate));
	$("#EGPPS")[0].innerHTML=(egpps*100).toFixed(2)+'%';
	
	var egppl = eprofitl/(eprofitl+parseFloat(1.2*$("#NID_Cost").val()/rate));
	$("#EGPPL")[0].innerHTML=(egppl*100).toFixed(2)+'%';
}

/*]]>*/
</script>
